<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 华哥
  Date: 2021/5/12
  Time: 9:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%
        //获取项目的根路径
        String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <meta charset="utf-8">
    <title>湖南省长沙市华子医院</title>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>swee/sweetalert.css">
    <script type="text/javascript" src="<%=basePath%>swee/sweetalert-dev.js"></script>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css"  media="all">

    <style type="text/css">
        .biaodan{
           margin-top: 50px;
            text-align: center;
        }
        .biaodan input[type="text"]{
            width: 150px;
            height: 25px;
        }
       #selectStatus{
        margin-left: 100px;
       }
        .box-details{
            width: 350px;
            height: 300px;
            background: #009688;
            position: absolute;
            top: 250px;
            right: 550px;
            z-index: 10;
        }
        .span2{
            display: inline-block;
            width: 80px;
            text-align: center;
            color: white;
        }
        .box-details ul{
            margin-top: 10px;
        }
        .exit{
            position: absolute;
            top: 250px;
            right: 140px;
        }
    </style>
    <link rel="shortcut icon" href="#"/>
</head>
<body>
    <form action="<%=basePath%>mendicne?tp=select&applystatu=0" method="post" class="biaodan">
      <p>  申请人：<input type="text" name="name">&nbsp;&nbsp;&nbsp;药&nbsp;&nbsp;&nbsp;名： <input type="text" name="yaoName">
          &nbsp;&nbsp;&nbsp;<input type="submit" value="查询" class="layui-btn layui-btn-radius">
          <a href="<%=basePath%>mendicne?tp=selectStatus&applystatu=1" id="selectStatus" class="layui-btn layui-btn-radius">
            查询已同意
          </a>
      </p>
    </form>
    <table class="layui-table" lay-even="" lay-skin="nob">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>编号</th>
            <th>申请人</th>
            <th>申请时间</th>
            <th>药总类</th>
            <th>药名</th>
            <th>药类型</th>
            <th>单价</th>
            <th>数量</th>
            <th>申请类型</th>
            <th>处理类型</th>
            <th>备注</th>
            <th>操作</th>

        </tr>
        </thead>
        <tbody>
        <c:forEach items="${page.newsList}" var="list">
            <tr>
                <td>${list.id}</td>
                <td>${list.applycat}</td>
                <td>${list.applytime}</td>
                <td>${list.drugspecies}</td>
                <td>${list.applydrug}</td>
                <td>${list.drugtype}</td>
                <td>${list.price}</td>
                <td>${list.count}</td>
                <td>${list.type}</td>
                <td id="color">${list.statu}</td>
                <td>${list.remark}
                <td><c:if test="${id==1}">
                    <a href="javascript:void(0)" onclick="consents(${list.id})" class="layui-btn layui-btn-sm">同意</a>
                </c:if>

                <a href="javascript:void(0)" class="detas">详情</a>
<%--                <button type="button" class="layui-btn layui-btn-sm"  onclick="details(${list.applytime})"><i class="layui-icon"></i></button>--%>

                <c:if test="${id==0}">
                   <a href="javascript:void(0)" onclick="del(${list.id})" class="layui-btn layui-btn-sm">删除</a>
                </c:if>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div class="box-details" hidden>
        <table class="layui-table" lay-skin="line">

            <thead>
            <tr>
                <th>编号</th>
                <th>药名</th>
                <th>单价</th>
                <th>数量</th>
            </tr>
            </thead>
            <tbody id="he">

            </tbody>
        </table>
        <button type="button" class="layui-btn layui-btn-normal exit">关闭</button>
    </div>

    <p style="text-align: center">
        <c:if test="${requestScope.page.currPageNo>1}">
            <a href="<%=basePath%>mendicne?currentPage=${requestScope.page.currPageNo-1}&tp=select"  class="layui-btn layui-btn-primary layui-border-blue">上一页</a>
        </c:if>
        <%--    <a href="<%=basePath%>bill?currentPage=${requestScope.page.currPageNo-1}&tp=select"  class="layui-btn layui-btn-primary layui-border-blue">上一页</a>--%>
        ${requestScope.page.currPageNo}/ ${requestScope.page.totalPageCount}
        <c:if test="${requestScope.page.currPageNo<requestScope.page.totalPageCount}">
            <a href="<%=basePath%>mendicne?currentPage=${requestScope.page.currPageNo+1}&tp=select" class="layui-btn layui-btn-primary layui-border-blue">下一页</a>
        </c:if>
    </p>

    <script type="text/javascript" src="<%=basePath%>jquery/jquery-1.12.4.js"></script>
    <script src="<%=basePath%>layui-v2.6.5/layui/layui.js" charset="utf-8"></script>

    <script type="text/javascript">
        $(function () {
        $(".exit").click(function () {
            $(".box-details").hide();
        })
            
            $(".detas").click(function () {

                let time = $(this).parent().parent().children("td:eq(2)").text();
                $.ajax({
                        url:"<%=basePath%>mendicne",
                        type:"post",
                        data:{
                            time:time,
                            tp:"details"
                        },
                        dataType:"json",
                        success:function (data) {
                            let lis =``;
                            for (let i = 0; i < data.length; i++) {
                            lis += `<tr>
                <td>`+(data[i].id)+`</td>
                <td>`+(data[i].drugName)+`</td>
                 <td>`+(data[i].price)+`</td>
                 <td>`+(data[i].count)+`</td>
                </tr>`;
                            }
                            $("#he").html(lis);
                            $(".box-details").show();
                        }
                    });

            })
            
            
            
        })

        // function detas(id) {
            // alert(11);
            <%--$.ajax({--%>
            <%--        url:"<%=basePath%>mendicne",--%>
            <%--        type:"post",--%>
            <%--        data:{--%>
            <%--            id:id,--%>
            <%--            tp:"details"--%>
            <%--        },--%>
            <%--        dataType:"json",--%>
            <%--        success:function (data) {--%>
            //             let lis = ``;
            <%--            for (let i = 0; i < data.length; i++) {--%>
            //             lis += `<tr>
                                          <%--<td>${data[i].id}</td>--%>
                                          <%--<td>${data[i].drugName}</td>--%>
                                          <%-- <td>${data[i].price}</td>--%>
                                          <%-- <td>${data[i].count}</td>--%>
                                        //    <td>123</td>
                                        //   <td>123</td>
                                        //    <td>123</td>
                                        //    <td>123</td>
                                        // </tr>`;
            <%--            }--%>
            //             $("#he").html(lis);
            //             $(".box-details").show();
            <%--        }--%>
            <%--    });--%>
        // }

        function consents(id) {

            swal({
                    title: "确定同意申请吗？",
                    text: "你将无法恢复该虚拟文件！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定同意！",
                    cancelButtonText: "取消同意！",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function(isConfirm){
                    if (isConfirm) {
                            $.ajax(
                                {
                                    url:"<%=basePath%>mendicne",
                                    type:"post",
                                    data:{
                                        id:id,
                                        tp:"consent"
                                    },
                                    dataType:"json",
                                    success:function (data) {
                                        swal("审核通过", "成功",
                                            "success");
                                        location.reload();
                                    }
                                });

                    } else {
                        swal("取消！", "你的虚拟文件是安全的！",
                            "error");
                    }
                });

            }


        function del(ids) {
            swal({
                    title: "确定删除吗？",
                    text: "你将无法恢复该虚拟文件！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定删除！",
                    cancelButtonText: "取消删除！",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function(isConfirm){
                    if (isConfirm) {
                        $.ajax(
                            {
                                url:"<%=basePath%>mendicne",
                                data:{
                                    ids:ids,
                                    tp:"del"
                                },
                                type:"post",
                                dataType:"json",
                                success:function (data) {
                                    swal("删除成功！", "你的虚拟文件已经被删除。",
                                        "success");
                                    // location.reload();
                                }
                            });

                    } else {
                        swal("取消！", "你的虚拟文件是安全的:)",
                            "error");
                    }
                });
        
        }

    </script>
</body>
</html>
